package com.fr.report.script.core.parser;

import com.fr.base.core.ComparatorUtils;
import com.fr.report.script.Calculator;
import com.fr.report.script.core.FArray;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class RelationExpression extends MathExpression
{
  private static final String GT = ">";
  private static final String LT = "<";
  private static final String GE = ">=";
  private static final String LE = "<=";
  private static final String EQ = "=";
  private static final String NE1 = "!=";
  private static final String NE2 = "<>";
  AddExpression left;
  String op;
  AddExpression right;

  RelationExpression(AddExpression paramAddExpression1, String paramString, AddExpression paramAddExpression2)
  {
    this.left = paramAddExpression1;
    this.op = paramString;
    this.right = paramAddExpression2;
  }

  private static Boolean onEQ(String paramString)
  {
    return Boolean.valueOf((">=".equals(paramString)) || ("<=".equals(paramString)) || ("=".equals(paramString)));
  }

  private static Boolean onLT(String paramString)
  {
    return Boolean.valueOf(("<".equals(paramString)) || ("<=".equals(paramString)) || ("!=".equals(paramString)) || ("<>".equals(paramString)));
  }

  private static Boolean onGT(String paramString)
  {
    return Boolean.valueOf((">".equals(paramString)) || (">=".equals(paramString)) || ("!=".equals(paramString)) || ("<>".equals(paramString)));
  }

  public Object eval(Calculator paramCalculator)
    throws UtilEvalError
  {
    if (this.left == null)
      throw new InterpreterError("left of RelationExpression should not be empty");
    Object localObject = this.left.eval(paramCalculator);
    if ((this.op != null) && (this.right != null))
      localObject = binaryOperation(localObject, this.right.eval(paramCalculator), this.op);
    return localObject;
  }

  protected Object arrayBinaryOperation(FArray paramFArray1, FArray paramFArray2, String paramString)
  {
    boolean bool = true;
    if (paramFArray1.length() == paramFArray2.length())
    {
      i = 0;
      j = paramFArray1.length();
      while (true)
      {
        if (i >= j)
          break label63;
        if (!((bool = ComparatorUtils.equals(paramFArray1.elementAt(i), paramFArray2.elementAt(i)))))
          break label63:
        ++i;
      }
    }
    bool = false;
    if (bool)
      label63: return (((">=".equals(paramString)) || ("<=".equals(paramString)) || ("=".equals(paramString))) ? Boolean.TRUE : Boolean.FALSE);
    if ("=".equals(paramString))
      return Boolean.FALSE;
    if (("!=".equals(paramString)) || ("<>".equals(paramString)))
      return Boolean.TRUE;
    int i = Math.min(paramFArray1.length(), paramFArray2.length());
    int j = 0;
    for (int k = 0; (k < i) && (j == 0); ++k)
      j = ComparatorUtils.compare(paramFArray1.elementAt(k), paramFArray2.elementAt(k));
    if (j == 0)
      j = paramFArray1.length() - paramFArray2.length();
    if (j > 0)
      return (((">".equals(paramString)) || (">=".equals(paramString))) ? Boolean.TRUE : Boolean.FALSE);
    if (j < 0)
      return (((">".equals(paramString)) || (">=".equals(paramString))) ? Boolean.FALSE : Boolean.TRUE);
    return Boolean.FALSE;
  }

  protected boolean isRelationExpression()
  {
    return true;
  }

  protected Object ccNINI(String paramString)
  {
    return onEQ(paramString);
  }

  protected Object ccNIPI(String paramString)
  {
    return onLT(paramString);
  }

  protected Object ccNIRE(Object paramObject, String paramString)
  {
    return onLT(paramString);
  }

  protected Object ccPINI(String paramString)
  {
    return onGT(paramString);
  }

  protected Object ccPIPI(String paramString)
  {
    return onEQ(paramString);
  }

  protected Object ccPIRE(Object paramObject, String paramString)
  {
    return onGT(paramString);
  }

  protected Object ccRENI(Object paramObject, String paramString)
  {
    return onGT(paramString);
  }

  protected Object ccREPI(Object paramObject, String paramString)
  {
    return onLT(paramString);
  }

  protected Object ccRERE(Object paramObject1, Object paramObject2, String paramString)
  {
    if ((paramObject1 instanceof Number) && (paramObject2 instanceof Number))
      return numberOperation(paramObject1, paramObject2, paramString);
    if (ComparatorUtils.equals(paramObject1, paramObject2))
      return onEQ(paramString);
    if (ComparatorUtils.compare(paramObject1, paramObject2) > 0)
      return onGT(paramString);
    return onLT(paramString);
  }

  protected Object decimalOperation(BigDecimal paramBigDecimal1, BigDecimal paramBigDecimal2, String paramString)
  {
    return compareOperation(ComparatorUtils.compare(paramBigDecimal1, paramBigDecimal2), paramString);
  }

  protected Object doubleOperation(double paramDouble1, double paramDouble2, String paramString)
  {
    return compareOperation(ComparatorUtils.compare(paramDouble1, paramDouble2), paramString);
  }

  protected Object intOperation(int paramInt1, int paramInt2, String paramString)
  {
    return compareOperation(paramInt1 - paramInt2, paramString);
  }

  private Object compareOperation(double paramDouble, String paramString)
  {
    if (paramDouble == 0.0D)
      return onEQ(paramString);
    if (paramDouble > 0.0D)
      return onGT(paramString);
    return onLT(paramString);
  }

  public void traversal4Tiny(TinyHunter paramTinyHunter)
  {
    if (this.left != null)
      this.left.traversal4Tiny(paramTinyHunter);
    if (this.right != null)
      this.right.traversal4Tiny(paramTinyHunter);
  }

  public String exString(Calculator paramCalculator)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append(this.left.exString(paramCalculator));
    if ((this.op != null) && (this.right != null))
      localStringBuffer.append(' ').append(this.op).append(' ').append(this.right.exString(paramCalculator));
    return localStringBuffer.toString();
  }

  public String toString()
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append(this.left);
    if ((this.op != null) && (this.right != null))
      localStringBuffer.append(' ').append(this.op).append(' ').append(this.right);
    return localStringBuffer.toString();
  }

  public String getExpression(int paramInt1, int paramInt2, int paramInt3, int paramInt4, boolean paramBoolean)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append(this.left.getExpression(paramInt1, paramInt2, paramInt3, paramInt4, paramBoolean));
    if ((this.op != null) && (this.right != null))
      localStringBuffer.append(' ').append(this.op).append(' ').append(this.right.getExpression(paramInt1, paramInt2, paramInt3, paramInt4, paramBoolean));
    return localStringBuffer.toString();
  }

  public String[] parserParameter()
  {
    ArrayList localArrayList = new ArrayList();
    localArrayList.addAll(Arrays.asList(this.left.parserParameter()));
    if ((this.op != null) && (this.right != null))
      localArrayList.addAll(Arrays.asList(this.right.parserParameter()));
    return ((String[])localArrayList.toArray(new String[localArrayList.size()]));
  }
}